package com.oak.designmode._14_observeParttern.school;

import java.util.Vector;

/**
 * 班长（发布消息）
 * @Description
 * @Author guoxy
 * @Date 2020/3/18
 * @Version 1.0
 */
public class Monitor {

    /** 学生数组，vecor线程安全 */
    private Vector<Student> oVector = new Vector<>();

    /**
     * 增加一个观察者
     * @param student
     */
    public void addObserver(Student student) {
        this.oVector.add(student);
    }

    /**
     * 删除一个观察者
     * @param student
     */
    public void deleteObserver(Student student) {
        this.oVector.remove(student);
    }

    /**
     * 通知同学
     */
    public void notifyObserver() {
        for(Student student : this.oVector) {
            // 更新状态
            student.update();
        }
    }

}
